import 'package:flutter/material.dart';

class CellGroup extends StatelessWidget {
  final List<Widget> cellList;
  final Color bgColor;
  Color boxShadowColor;
  bool showShadow;
  CellGroup(
      {Key key,
      this.cellList,
      this.bgColor = Colors.white,
      this.boxShadowColor = Colors.white,
      this.showShadow = false});

  @override
  Widget build(BuildContext context) {
    return Container(
        child: ConstrainedBox(
      constraints: BoxConstraints(
        maxHeight: MediaQuery.of(context).size.height - 100,
        minWidth: double.infinity, // //宽度尽可能大
      ),
      child: ListView(
        shrinkWrap: true,
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(left: 15, right: 15),
            decoration: BoxDecoration(
                color: bgColor,
                borderRadius: BorderRadius.all(
                  Radius.circular(5.0),
                ),
                boxShadow: showShadow
                    ? [
                        BoxShadow(
                          color: boxShadowColor,
                          offset: Offset(1, 1),
                          blurRadius: 1,
                          spreadRadius: 1,
                        )
                      ]
                    : []),
            child: Column(
              // shrinkWrap: true,
              children: cellList,
            ),
            // children: cellList,
          )
        ],
      ),
    ));
  }
}

class Cell extends StatelessWidget {
  final String title;
  final String value;
  final String placeholder;
  final Function onTap;
  final bool showIcon;
  final IconData customIcon;
  final Widget customContent;
  final bool lastCell;
  final Widget cellBodyContent;
  final Color titleColors;
  final double titleFontSize;
  final Color valueColor;

  Cell({
    Key key,
    this.title = "单元格",
    this.value = " ",
    this.placeholder,
    this.onTap,
    this.showIcon = false,
    this.customIcon = Icons.arrow_forward_ios_rounded,
    this.customContent,
    this.lastCell = false,
    this.cellBodyContent,
    this.titleColors,
    this.titleFontSize = 14,
    this.valueColor,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: 15, bottom: 15),
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(
              color: lastCell
                  ? Color.fromRGBO(255, 255, 255, 0)
                  : Color.fromRGBO(240, 240, 240, 1)),
        ),
      ),
      child: Flex(direction: Axis.horizontal, //必填属性
          children: <Widget>[
            Expanded(
                child: Container(
              child: Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Container(
                        child: ConstrainedBox(
                          constraints: BoxConstraints(maxWidth: 215),
                          child: Text(
                            title,
                            style: TextStyle(
                                color: titleColors, fontSize: titleFontSize),
                            overflow: TextOverflow.ellipsis,
                          ),
                        ),
                      ),
                      customContent ?? _defaultCellContent()
                    ],
                  ),
                  Container(
                    child: cellBodyContent ?? Container(),
                  )
                ],
              ),
            ))
          ]),
    );
  }

  Widget _defaultCellContent() {
    return Container(
        child: InkWell(
      onTap: onTap,
      child: Row(
        children: [
          value == "" || value == null
              ? Text(placeholder, style: TextStyle(color: Colors.black12))
              : Text(
                  value,
                  style: TextStyle(color: valueColor),
                ),
          showIcon
              ? Icon(
                  customIcon,
                  size: 15,
                  color: Colors.black45,
                )
              : Container(),
        ],
      ),
    ));
  }
}
